package pack0815;

import java.util.Scanner;

public class Atm {
    int pass = 123456;
    int money = (int)(Math.random()*2000000+200);
    Scanner in = new Scanner(System.in);
    int errorNum = 0;
    //登录
    public void login(){
        System.out.println("欢迎使用**银行ATM机");
        System.out.println("请输入密码：");
        int pass = in.nextInt();
        if(this.pass==pass){
            mainView();
            errorNum = 0;
        }else {
            errorNum++;
            if(errorNum <3){
                System.out.println("密码输入错误，请重新输入！");
                login();
            }else{
                System.out.println("密码输入错误三次，已吞卡！\n 请拿身份证到前台办理取卡");
            }
        }
    }
    //操作界面
    public void mainView(){
        System.out.println("*******************************");
        System.out.println("欢迎登陆中国**银行");
        System.out.println("*******************************");
        System.out.println("1.取款");
        System.out.println("2.存款");
        System.out.println("3.查询");
        System.out.println("4.改密");
        System.out.println("5.退出");
        int a = in.nextInt();
        if(a==1){
            quKuan();
        }else if(a==2){
            cunKuan();
        }else if(a==3){
            chaXun();
        }else if(a==4){
            gaiMi();
        }else if(a==5){
            tuiChu();
        }else{
            System.out.println("请正确输入：");
            mainView();
        }
    }
    public void quKuan(){
        System.out.println("请输入取款金额：");
        int a = in.nextInt();
        if(a%100!=0){
            System.out.println("只能取面值为100的钞票,请重新输入！");
            quKuan();
        }else if(a>10000){
            System.out.println("单次取款要少于10000元，请重新输入！");
            quKuan();
        }else if(a>money){
            System.out.println("你的余额不足，请重新输入！");
            mainView();
        }else{
            System.out.println("取款成功");
            money -= a;
            mainView();
        }
    }
    public void cunKuan(){
        System.out.println("请放入面值为100元的钞票：");
        int a = in.nextInt();
        if(a%100!=0){
            System.out.println("只能存入面值为100元的钞票，请重新输入！");
            cunKuan();
        }else {
            System.out.println("存款成功");
            money += a;
            mainView();
        }
    }
    public void chaXun(){
        System.out.println("你的余额是："+money+"元");
        mainView();
    }
    public void gaiMi(){
        System.out.println("请输入密码：");
        int a = in.nextInt();
        if(a==pass){
            System.out.println("请输入新密码：");
            int b = in.nextInt();
            if(b>99999&&b<1000000){
                System.out.println("请再次输入密码：");
                int c = in.nextInt();
                if(b==c){
                    System.out.println("密码修改成功，请重新登陆！");
                    pass = b;
                    login();
                }else{
                    System.out.println("两次密码输入不一致，请重新输入！");
                    gaiMi();
                }
            }else{
                System.out.println("请输入正确的六位数密码：");
                gaiMi();
            }
        }else{
            System.out.println("密码输入错误，请重新登陆！");
            login();
        }
    }
    public void tuiChu(){
        System.out.println("退出\n欢迎下次光临！");
    }

    public static void main(String[] args) {
        Atm bd = new Atm();
        bd.login();
    }
}